//
//  HYRootXiangQingViewController.m
//  qiJi
//
//  Created by 凤利史 on 2018/4/3.
//  Copyright © 2018年 sunrose. All rights reserved.
//

#import "HYRootXiangQingViewController.h"
#import "HYRootXiangQFirstTableViewCell.h"
#import "HYRootXiangQSecTableViewCell.h"
#import "HYRootXiangQThreTableViewCell.h"
#import "HYRootXiangQFourTableViewCell.h"
#import "HYRootXiangQFiveTableViewCell.h"
#import "HYRootXiangQFistSectionView.h"
@interface HYRootXiangQingViewController ()<UITableViewDelegate , UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArr;
@property (nonatomic, strong) UITextField *commentTextField;
@property (nonatomic, strong) UILabel *pingLunLab;//评论数
@property (nonatomic, strong) UILabel *dianZanLab;//点赞数
@property (nonatomic, strong) UIButton *pingLunBtn;//评论
@property (nonatomic, strong) UIButton *dianZanBtn;//点赞
@end

@implementation HYRootXiangQingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"详情";
    [self creationView];
    [self regeditCell];
   
    
    // Do any additional setup after loading the view.
}
- (void)creationView{
    
    
    
    self.tableView = [[UITableView alloc] init];
    self.tableView.frame = CGRectMake(0, 2, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - (KIsiPhoneX?84:64) - 62);
    
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.estimatedRowHeight = 800;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    UIView *threadView = [[UIView alloc]initWithFrame:CGRectMake(0, 1, DEF_SCREEN_WIDTH, 1)];
    threadView.backgroundColor = getColor(@"E6E6E6");
    [self.view addSubview:threadView];
    /////////////下面view
    UIView *footView = [[UIView alloc] init];
    [self.view addSubview:footView];
    [footView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.bottom.equalTo(self.view);
        make.height.offset(60);
        
    }];
    footView.backgroundColor = [UIColor whiteColor];
   
    
    UIView *lineView = [[UIView alloc] init];
    [footView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.top.equalTo(footView);
        make.height.offset(1);
        
    }];
    lineView.backgroundColor = getColor(@"E6E6E6");
    
    self.commentTextField = [[UITextField alloc] init];
    [footView addSubview:self.commentTextField];
    [self.commentTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(footView).with.offset(25);
        make.height.offset(40);
        make.top.equalTo(footView).with.offset(10);
        make.right.equalTo(footView).with.offset(-150*CHANGE_SIZE);
        
    }];
    self.commentTextField.backgroundColor = getColor(@"F2F2F2");
    self.commentTextField.placeholder = @"说点什么吧";
    self.commentTextField.font = [UIFont systemFontOfSize:12];
    
    self.pingLunLab = [[UILabel alloc] init];
    [footView addSubview:self.pingLunLab];
    [self.pingLunLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(footView).with.offset(-25);
        make.centerY.equalTo(footView);
       // make.width.offset(40*CHANGE_SIZE);
        
    }];
    self.pingLunLab.text = @"555";
    self.pingLunLab.textColor = getColor(@"333333");
    self.pingLunLab.font = [UIFont systemFontOfSize:12];
    
    self.pingLunBtn = [[UIButton alloc] init];
    [footView addSubview:self.pingLunBtn];
    [self.pingLunBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.pingLunLab.mas_left).with.offset(-5);
        make.centerY.equalTo(footView);
    }];
    [self.pingLunBtn setBackgroundImage:[UIImage imageNamed:@"particulars_comment_icon"] forState:UIControlStateNormal];
    
    
    self.dianZanLab= [[UILabel alloc] init];
    [footView addSubview:self.dianZanLab];
    [self.dianZanLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.pingLunBtn.mas_left).with.offset(-10);
        make.centerY.equalTo(footView);
        // make.width.offset(40*CHANGE_SIZE);
        
    }];
    self.dianZanLab.text = @"555";
    self.dianZanLab.textColor = getColor(@"333333");
    self.dianZanLab.font = [UIFont systemFontOfSize:12];
    
    
    self.dianZanBtn = [[UIButton alloc] init];
    [footView addSubview:self.dianZanBtn];
    [self.dianZanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.dianZanLab.mas_left).with.offset(-5);
        make.centerY.equalTo(footView);
    }];
    [self.dianZanBtn setBackgroundImage:[UIImage imageNamed:@"particulars_comment_praise_nor_icon"] forState:UIControlStateNormal];
    
    
    
    
    
    
}
- (void)regeditCell{
    
    [self.tableView registerNib:[UINib nibWithNibName:@"HYRootXiangQFirstTableViewCell" bundle:nil] forCellReuseIdentifier:@"HYRootXiangQFirstTableViewCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"HYRootXiangQSecTableViewCell" bundle:nil] forCellReuseIdentifier:@"HYRootXiangQSecTableViewCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"HYRootXiangQThreTableViewCell" bundle:nil] forCellReuseIdentifier:@"HYRootXiangQThreTableViewCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"HYRootXiangQFourTableViewCell" bundle:nil] forCellReuseIdentifier:@"HYRootXiangQFourTableViewCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"HYRootXiangQFiveTableViewCell" bundle:nil] forCellReuseIdentifier:@"HYRootXiangQFiveTableViewCell"];
    
    
    
    [_tableView registerNib:[UINib nibWithNibName:@"HYRootXiangQFistSectionView" bundle:nil] forHeaderFooterViewReuseIdentifier:@"HYRootXiangQFistSectionView"];
    
};

#pragma mark - ---------- Section的数量 ----------
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

#pragma mark - ---------- 每个Section的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    
    if (section == 1) {
        return 55;
    }else{
        
        return 0;
    }
    
    
}

//section 不随tableView滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    if (scrollView == self.tableView)
        
    {
        
        CGFloat sectionHeaderHeight = 64; //header高度
        
        if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0) {
            
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
            
        } else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
            
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
            
        }
        
    }
    
    
    
}
#pragma mark - ---------- Section的内容 ----------
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section == 1) {
        HYRootXiangQFistSectionView *sectionView = [self.tableView dequeueReusableHeaderFooterViewWithIdentifier:@"HYRootXiangQFistSectionView"];
        
        return sectionView;
    }else{
        
        return nil;
        
    }
    
    
    
    
    
    
}
#pragma mark - ---------- 每个Cell的高度 ----------
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return 65;
        }else if (indexPath.row == 1){
            return 115;
        }else {
            return UITableViewAutomaticDimension;
        }
    }else{
        
        return UITableViewAutomaticDimension;
    }
    
}
#pragma mark - ---------- 每个Cell的点击事件 ----------
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
}

#pragma mark - ---------- Cell的数量 ----------

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
        return 4;
    }else{
        
        return 8;
    }
}
#pragma mark - ---------- 每个Cell的内容 ----------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            HYRootXiangQFirstTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"HYRootXiangQFirstTableViewCell" forIndexPath:indexPath];
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
        }else if (indexPath.row == 1){
            HYRootXiangQSecTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"HYRootXiangQSecTableViewCell" forIndexPath:indexPath];
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            
            
            return cell;
            
        }else if (indexPath.row == 2){
            HYRootXiangQThreTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"HYRootXiangQThreTableViewCell" forIndexPath:indexPath];
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            
            
            return cell;
            
        }else{
            HYRootXiangQFourTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"HYRootXiangQFourTableViewCell" forIndexPath:indexPath];
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            
            
            return cell;
            
        }
    }else{
        HYRootXiangQFiveTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"HYRootXiangQFiveTableViewCell" forIndexPath:indexPath];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        
        
        return cell;
        
    }
    
   
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
